<template>
	<view class="container">
		<view class="topview">
			<view class="banner_bg">
				<image :src="userInfo.pictureUrl" mode="" v-if="userInfo.pictureUrl"></image>
				<image :src="pictureUrl" mode="" v-if="!userInfo.pictureUrl"></image>
			</view>

			<view class="perinfo" @click="login">
				<view class="pho">
				<image :src="userInfo.pictureUrl" mode="" v-if="userInfo.pictureUrl"></image>
				<image :src="pictureUrl" mode="" v-if="!userInfo.pictureUrl"></image>
				</view>
				<!-- 				<view class="pho">
				      <open-data type="userAvatarUrl"></open-data>
				</view> -->

				<view class="adoptedland">
					<view class="topland">
						<!-- <open-data type="userNickName"></open-data> -->
						{{userInfo.nickname}}
					</view>
					<view class="bottomland">
						id：{{userInfo.id}}
					</view>
				</view>


			</view>
		</view>




		<view class="orderContent-box">

			<view class="orderContent-item" @click="toorderlist">
				<image src="@/static/travel.png" alt=""></image>
				<text>我的交易</text>
				<view></view>
				<image src="@/static/right.png" alt=""></image>
			</view>
			<view class="orderContent-item" @click="tohostlist">
				<image src="@/static/coll.png" alt=""></image>
				<text>我的收藏</text>
				<view></view>
				<image src="@/static/right.png" alt=""></image>
			</view>

			<view class="orderContent-item" @click="toaddress">
				<image src="@/static/rules.png" alt=""></image>
				<text>平台规则</text>
				<view></view>
				<image src="@/static/right.png" alt=""></image>
			</view>
			<view class="orderContent-item" @click="toAuthority">
				<image src="@/static/help.png" alt=""></image>
				<text>帮助中心</text>
				<view></view>
				<image src="@/static/right.png" alt=""></image>
			</view>
			<view class="orderContent-item" @click="tosetting">
				<image src="@/static/set-up-dot.png" alt=""></image>
				<text>我的设置</text>
				<view></view>
				<image src="@/static/right.png" alt=""></image>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: null,
				userInfo: {
					nickname: '游客1024',
					pictureUrl: 'https://lnnu-tuchuang.oss-cn-guangzhou.aliyuncs.com/farm/2023-03-19/6cb643b7-3ec4-4df3-a32e-4f07f204e51e5273490086447757152.jpg',
					id: '0052'
				},
				pictureUrl: 'https://lnnu-tuchuang.oss-cn-guangzhou.aliyuncs.com/farm/2023-03-19/6cb643b7-3ec4-4df3-a32e-4f07f204e51e5273490086447757152.jpg',
				info: {},
				changeNum: '1'

			}

		},

		// onShow() {
		// 	const num = uni.getStorageSync('changeNum');
		// 	// console.log(num);
		// 	if (num == '3') {
		// 		const globalValue = uni.getStorageSync('userInfo');
		// 		const nickname = uni.getStorageSync('nickname');
		// 		const pictureUrl = uni.getStorageSync('pictureUrl');
		// 		const id = uni.getStorageSync('id');
		// 		this.userInfo.nickname = nickname
		// 		this.userInfo.pictureUrl = pictureUrl
		// 		this.userInfo.id = id


		// 	} else  {
		// 		const globalValue = uni.getStorageSync('userInfo');
		// 		const id = uni.getStorageSync('id');
		// 		if(globalValue) {
		// 			this.userInfo.nickname = globalValue.nickname
		// 			this.userInfo.pictureUrl = globalValue.pictureUrl
		// 			this.userInfo.id = id
		// 		} else {

		// 			this.userInfo.nickname='登录'
		// 			this.userInfo.pictureUrl='https://lnu-market.oss-cn-guangzhou.aliyuncs.com/2022-10-06/16:22:29-8b47bee75ce5400792163d304d21f7b4.jpg'
		// 			this.userInfo.id = id

		// 		}
		// 	}
		// },
		onPullDownRefresh() {
			// console.log('触发了下拉刷新')
			setTimeout(() => {
				uni.stopPullDownRefresh()
				const pages = getCurrentPages()
				//声明一个pages使用getCurrentPages方法
				const perpage = pages[pages.length - 1]
				//声明一个当前页面
				perpage.onLoad()
				//执行刷新
			}, 1000)
		},

		//分享
		onShareTimeline() {
			return {
				path: "pages/my/my", //不设置默认当前页面
				title: "岭师墙",
				imageUrl: "https://xingqiu-tuchuang-1256524210.cos.ap-shangha…23-02-02/ea369ef3-87b5-4756-b2fe-5ec5a46c2445.jpg" //不设置默认截取页面
			}
		},

		onShareAppMessage(res) {
			// return eventHandler接收到的分享参数
			return {
				title: '岭师墙', // 分享名称
				path: 'pages/my/my', // 这里写你这个页面的路径
				imageUrl: '', //这个是显示的图片，不写就默认当前页面的截图
				success(shareTickets) {
					console.log(shareTickets + '成功');
					uni.showToast({
						title: '提交成功',
						duration: 1500
					})
					// 转发成功
				},
				fail: function(res) {
					console.log(res + '失败');
					// 转发失败
				},
				complete: function(res) {
					// 不管成功失败都会执行
				}
			}
		},

		methods: {

			login() {
				uni.getUserProfile({
					desc: "获取你的昵称、头像、地区及性别",
					success: (res) => {
						// console.log("用户信息", JSON.stringify(res.userInfo))
						this.userInfo.nickname = "用户3306"
						// console.log(cardInfo.userInfo);
						uni.login({
							provider:'weixin',
							success: (res2) => {
								// uni.showLoading({
								// 	title:"登陆中"
								// })
								//获得code
								console.log(res2);
								var code = res2.code
								// console.log(code);
								uni.request({
									url:'',
									method:'POST',
									data:{
										info: JSON.stringify({
											"code":code,
											"nickName": this.userInfo.nickname,
											"avatarUrl": this.userInfo.pictureUrl
										})
									},
									success:(res3)=>{
										console.log(userInfo);
										console.log(res3);	
									},
									fail: (err) => {
										console.log(err);
									}
								})
							},
				
						})
						
						
						
					},
					fail() {
				
					}
				})
				// uni.login({
				// 	provider: 'weixin',
				// 	success: (res) => {
				// 		uni.showLoading({
				// 			title: '加载中'
				// 		});
				// 		this.code = res.code;
				// 		console.log(res.code);
				// 		if (res.code) {
				// 			wechatLogin({
				// 				code: res.code,

				// 			}).then(res => {
				// 				console.log(res);
				// 				this.userInfo.nickname = res.data.data.nickname
				// 				this.userInfo.id = res.data.data.id
				// 				this.userInfo.pictureUrl = res.data.data.pictureUrl

				// 				uni.setStorageSync('userInfo', res.data.data);
				// 				uni.setStorageSync('id', res.data.data.id);
				// 				uni.setStorageSync('token', res.data.data.token);
				// 				// const token = uni.getStorageSync('token')
				// 				// console.log();


				// 			})
				// 		}
				// 		uni.hideLoading();
				// 		if (this.changeNum == '2') {
				// 			uni.showModal({
				// 				title: '提示',
				// 				content: '是否更改头像昵称',
				// 				success: function(res) {
				// 					if (res.confirm) {
				// 						uni.navigateTo({
				// 							url: '/pages/inputInfo/inputInfo',
				// 							fail(error) {
				// 								console.log(error)
				// 							}
				// 						})
				// 					} else if (res.cancel) {

				// 					}
				// 				}
				// 			});
				// 		} else {
				// 			this.changeNum = 2
				// 			console.log('num', this.changeNum);
				// 		}
				// 	}
				// });
			},

			toPrivate() {
				uni.navigateTo({
					url: '/pages/PrivateMessage/PrivateMessage',
					fail(error) {
						console.log(error)
					}
				})
			},

			toaddress() {
				uni.navigateTo({
					url: '/pages/my/rules/rules',
					fail(error) {
						console.log(error)
					}
				})
			},

			tosetting() {
				uni.navigateTo({
					url: '/pages/Authority/Authority',
					fail(error) {
						console.log(error)
					}
				})
			},

			toAuthority() {
				uni.navigateTo({
					url: '/pages/my/help/help',
					fail(error) {
						console.log(error)
					}
				})
			},
			tohostlist() {
				uni.navigateTo({
					url: '../Collection/Collection'
				})
			},
			toorderlist() {
				uni.navigateTo({
					url: '../trading/trading'
				})
			},



		}
	}
</script>



<style lang="less" scoped>
	.container {
		width: 100%;
		height: 95vh;
		// background-color: rgb(242, 242, 242);
	}

	@keyframes identifier {
		from {
			transform: translateY(-1900px);
			// transform: translate(80,100);
		}

		to {
			transform: translateY(0px);

		}
	}

	.topview {
		position: relative;
		width: 100%;
		height: 30%;
		// background-image: linear-gradient(to top, #3daf5d, #67e26f);
		// border-radius:0 0 10px 10px;
		text-align: center;
		padding-top: 15%;
		box-sizing: border-box;

		.perinfo {
			width: 90%;
			height: 110px;
			background-color: #fff;
			border-radius: 10px;
			margin: 0 auto;
			padding: 15px 0;
			box-sizing: border-box;
			box-shadow: 0px 5px 10px 2px #dcdcdc;
			opacity: 0.99;

			.pho {
				display: inline-block;
				width: 80px;
				height: 80px;
				vertical-align: middle;
				margin-right: 30rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.adoptedland {
				display: inline-block;
				margin: 10px 0;
				vertical-align: middle;
				text-align-last: left;

				.topland {
					width: 380rpx;
					font-size: 22px;
					color: black;
					margin: -5px 0 10px;
					text-align-last: left;
				}

				.topland:active {
					color: #ccc;
				}

				.bottomland {
					width: 380rpx;
					color: #9d9d9d;
					text-align-last: left;
				}

			}
		}
	}

	.orderContent-box {
		display: grid;
		width: 100vw;
		margin-top: 60px;
		grid-template-rows: repeat(5, 120rpx);
		justify-items: center;

		.orderContent-item {
			display: grid;
			width: 100vw;
			grid-template-columns: 130rpx 190rpx auto 150rpx;
			line-height: 150rpx;
			justify-items: center;
			align-items: center;
			font-size: 19px;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.banner_bg {

		position: absolute;
		/* 一定要用绝对定位 */
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		filter: blur(10px) brightness(90%);
		/* 模糊半径 */
		z-index: -1;
		margin: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
